<template>
  <view class="page-customer">
    <view class="header">{{ $t('customer.客服') }}</view>
    <view class="content">
      <view class="customer-item" v-for="(item, index) in customerList" :key="index">
        <view class="name">{{ item.name }}:</view>
        <view class="avatar">
          <image :src="item.img.startsWith('http') ? item.img : `${imgUrl}${item.img}`" alt="" class="avatar-img" mode="aspectFill" />
          <!-- <image :src="`https://api.nanarea.cyou/api/sys/common/static/${item.img}`" alt="" class="avatar-img" mode="aspectFill" /> -->
          <view class="btn">
            <view class="contact" @click="handleCustomer(item)">{{ $t('customer.联系客服') }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
  import { customerList } from '@/api/customer.js'
  import config from '@/config'

  export default {
    data() {
      return {
        customerList: [],
        url: '',
        imgUrl: config.imgUrl
      }
    },
    onPullDownRefresh() {
      this.getCustomer()
      uni.stopPullDownRefresh()
    },
    methods: {
      getCustomer() {
        this.$modal.loading('loading', 'loading')
        customerList()
          .then((res) => {
            let { list } = res.result
            this.customerList = list
            this.$modal.closeLoading()
          })
          .catch((err) => {
            this.$modal.closeLoading()
          })
      },
      handleCustomer(item) {
        window.open(item.url)
        return
        let [url, params] = item.url?.split('?') || []
        this.$tab.navigateTo(`/pages/customer/csr?url=${url}&params=${encodeURIComponent(params)}`)
      }
    },
    created() {
      this.getCustomer()
    }
  }
</script>
<style scoped lang="scss">
  .page-customer {
    background-color: #fff;
    .header {
      background-color: #31b2b5;
      text-align: center;
      height: 44px;
      line-height: 44px;
      position: fixed;
      top: 0;
      width: 100vw;
      color: #fff;

      font-size: 26rpx;
      z-index: 9;
      .back-icon {
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        font-weight: normal;
      }
    }
    .content {
      margin-top: 140rpx;
      .customer-item {
        padding: 10px 26px;
        .name {
          color: #101011;
          font-size: 32rpx;
        }
        .avatar {
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;
          margin-bottom: 40px;
          margin-top: 32px;
          .avatar-img {
            width: 110px;
            height: 110px;
            border-radius: 100%;
          }
          .btn {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 40px;
            border-radius: 20px;
            background: #5cb1b4;
            color: #fff;
            font-size: 26rpx;

            margin-top: 20px;
            width: 70%;
            .contact {
              margin-left: 10rpx;
            }
          }
        }
      }
    }
  }
</style>
